﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
// Experimental/Exploratory
#if USE_FLEE
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Threading;
using BrainTechLLC.ThreadSafeObjects;
using Ciloci.Flee;

namespace BrainTechLLC
{
    public class VariableContainer
    {
        public double[] DVar;
        public string[] SVar;
        public readonly Dictionary<string, string> VariableMapping = new Dictionary<string, string>();

        public int DoubleVariableNumber = 0;
        public int StringVariableNumber = 0;

        public VariableContainer()
        {
            DVar = new double[100];
            SVar = new string[100];
        }

        public VariableContainer(int doubleVars, int stringVars)
        {
            DVar = new double[doubleVars];
            SVar = new string[stringVars];
        }

        public void AddNumericVariable(string varName)
        {
            VariableMapping.Add(varName, "DVar[" + DoubleVariableNumber.ToString() + "]");
            DoubleVariableNumber++;
        }

        public void AddStringVariable(string varName)
        {
            VariableMapping.Add(varName, "SVar[" + StringVariableNumber.ToString() + "]");
            StringVariableNumber++;
        }

        public string EvalString(string s)
        {
            string ret = s;
            VariableMapping.ForEach(kvp => { ret = ret.Replace(kvp.Key, kvp.Value); });
            return ret;
        }

        public void SetValue(string varName, string varValue)
        {
            string s = VariableMapping[varName];
            int index = Convert.ToInt32(s.Replace("SVar[", "").Replace("]", ""));
            
            if (index >= SVar.Length)
                throw new Exception("Not enough room for another string variable: " + varName);

            SVar[index] = varValue;
        }

        public void SetValue(string varName, double varValue)
        {
            string s = VariableMapping[varName];
            int index = Convert.ToInt32(s.Replace("DVar[", "").Replace("]", ""));

            if (index >= DVar.Length)
                throw new Exception("Not enough room for another double variable: " + varName);

            DVar[index] = varValue;
        }
    }
}

#endif